// pages/login/login.js
import {
  http
} from '../../utils/http'
Page({
  data: {
    name: '',
    password: ''
  },
  login(e) {
    http.request({
      url: '/login',
      data: {
        name: this.data.name,
        password: this.data.password
      },
      method: 'GET',
      header: {
        'content-type': 'application/json;charset=utf-8'
      },
      success(data) {
        if (data.data) {
          wx.showToast({
            title: `${data.data.name}登录成功!`,
            icon: 'success',
            mask: true,
            duration: 1000,
          })
          setTimeout(() => {
            wx.navigateTo({
              url: '/pages/home/home',
            })
          }, 1500)

        } else {
          wx.showToast({
            title: `登录失败!`,
            icon: 'error',
            mask: true,
            duration: 1500,
          })
        }
      }
    })
  }
})